/**
 * Witontek.com.
 * Copyright (c) 2012-2017 All Rights Reserved.
 */
package test.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * 
 * @author Long
 * @version $Id: JedisPool.java, v 0.1 2017年9月4日 下午4:47:27  xiaolong.ma  Exp $
 */
public class RbJedisPool {

    private static JedisPool pool;

    //静态代码初始化池配置    

    static {

        //创建jedis池配置实例    

        JedisPoolConfig config = new JedisPoolConfig();

        //设置池配置项值    

        //根据配置实例化jedis池    

        pool = new JedisPool(config, "120.26.71.193", 36379, 1500, "Witon@2017");

    }

    /**获得jedis对象*/

    public static Jedis getJedisObject() {

        return pool.getResource();

    }

    /**  
    
     * 测试jedis池方法  
    
     */

    public static void main(String[] args) {

        Jedis jedis = getJedisObject();//获得jedis实例                    

        //获取jedis实例后可以对redis服务进行一系列的操作    

        jedis.set("name", "zhuxun");

        System.out.println(jedis.get("name"));

        jedis.del("name");

        System.out.println(jedis.exists("name"));

    }
}
